package com.ftd.controller;

import com.ftd.DBConnection.DBConnection;
import com.ftd.model.Ebook;
import com.ftd.viewmodel.MapResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by apple on 16/7/30.
 */
@RestController
public class EbookViewController extends BaseController {

    @RequestMapping(value = "getEbookJson")
    public List<MapResult> getEbookJson() throws IOException {

        List<MapResult> mapList = new ArrayList<MapResult>();

        ArrayList list = (ArrayList) DBConnection.select1("ebookTable");
        for (int i = 0; i < list.size();i++) {
            Ebook ebook = (Ebook)list.get(i);
            System.out.print(ebook.geteBookName());
            MapResult mapResult = new MapResult();
            mapResult.put("bookName", ebook.geteBookName());
            mapResult.put("imageUrl", ebook.geteImageUrl());
            mapResult.put("review", ebook.geteBookReview());
            mapResult.put("reading", ebook.geteBookReading());

            mapList.add(mapResult);
        }

        return mapList;
    }

    @RequestMapping(value = "ebookView")
    public String ebookView(){

        return "ebookView";
    }
}
